const getTree = (arr,pkey,relatekey,pid = 0)=>{
    if(relatekey == ''){
        return [];
    }
    var tree = []
    arr.forEach(function(v,k){
        if(v[relatekey] == pid){
            var children = getTree(arr,pkey,relatekey,v[pkey])
            if(children){
                v['children'] = children
            }
            tree.push(v);
        }
    })
    return tree;
}
const deepCopy = (obj)=>{
    var type = function(t) {
        if (Object.prototype.toString.call(t) === '[object Object]') {
            return 'Object';
        }

        if (Object.prototype.toString.call(t) === '[object Array]') {
            return 'Array';
        }

        return 'basic';
    };

    var copy = function(c) {
        if (type(c) === 'basic') {
            return c;
        }

        var newObj = type(c) === 'Object' ? {} : [];

        for (var key in c) {
            if (c.hasOwnProperty(key)) {
                newObj[key] = copy(c[key]);
            }
        }

        return newObj;
    };

    return copy(obj);
}

export{ getTree ,deepCopy}